package com.yswy.common.wxOrder.V2.wxconfig;

import com.github.wxpay.sdk.WXPayConfig;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import java.io.ByteArrayInputStream;
import java.io.InputStream;

/**
 * @ClassName: WxAppletConfig
 * @Description: 微信小程序支付配置
 * @Author: Matt
 * @Date: 2020/11/11 10:57
 **/
@Component
public class WxPayConfig implements WXPayConfig {
    private static final Logger logger = LoggerFactory.getLogger(WxPayConfig.class);
    /**
     * appId
     */
    public String appId;
    /**
     * 商户号
     */
    public String mchId;
    /**
     * 商户名称, 如'XXX服务号'
     */
    public String mchName;

    /**
     * NO_CHECK：不校验真实姓名 FORCE_CHECK：强校验真实姓名
     */
    public String checkName = "NO_CHECK";
    /**
     * key
     */
    public String key;
    /**
     * 证书路径
     */
    public String certPath;
    /**
     * 回调地址
     */
    public String notifyUrl;
    /**
     * 提现地址
     */
    public String transUrl;

    public byte[] certData;

    public WxPayConfig() {
    }

//    public WxPayConfig(WxPayKey wxPayKey) {
//        try {
//            File file = new File(wxPayKey.getCertPath());
//            InputStream certStream = new FileInputStream(file);
//            this.certData = new byte[(int) file.length()];
//            int read = certStream.read(this.certData);
//            certStream.close();
//        } catch (Exception e) {
//            logger.error("微信支付证书加载错误 -文件:" + wxPayKey.getCertPath() + "没找到");
//            e.printStackTrace();
//        }
//
//        this.appId = wxPayKey.getAppId();
//        this.mchName = wxPayKey.getMchName();
//        this.mchId = wxPayKey.getMchId();
//        this.key = wxPayKey.getWxKey();
//        this.checkName = wxPayKey.getCheckName();
//        this.certPath = wxPayKey.getCertPath();
//        this.notifyUrl = wxPayKey.getNotifyUrl();
//        this.transUrl = wxPayKey.getTransUrl();
//    }

    @Override
    public String getAppID() {
        return appId;
    }

    @Override
    public String getMchID() {
        return mchId;
    }

    @Override
    public String getKey() {
        return key;
    }

    @Override
    public InputStream getCertStream() {
        return new ByteArrayInputStream(this.certData);
    }

    @Override
    public int getHttpConnectTimeoutMs() {
        return 0;
    }

    @Override
    public int getHttpReadTimeoutMs() {
        return 0;
    }

    public String getAppId() {
        return appId;
    }

    public void setAppId(String appId) {
        this.appId = appId;
    }

    public String getMchId() {
        return mchId;
    }

    public void setMchId(String mchId) {
        this.mchId = mchId;
    }

    public String getMchName() {
        return mchName;
    }

    public void setMchName(String mchName) {
        this.mchName = mchName;
    }

    public String getCheckName() {
        return checkName;
    }

    public void setCheckName(String checkName) {
        this.checkName = checkName;
    }

    public void setKey(String key) {
        this.key = key;
    }

    public String getCertPath() {
        return certPath;
    }

    public void setCertPath(String certPath) {
        this.certPath = certPath;
    }

    public String getNotifyUrl() {
        return notifyUrl;
    }

    public void setNotifyUrl(String notifyUrl) {
        this.notifyUrl = notifyUrl;
    }

    public String getTransUrl() {
        return transUrl;
    }

    public void setTransUrl(String transUrl) {
        this.transUrl = transUrl;
    }

    public byte[] getCertData() {
        return certData;
    }

    public void setCertData(byte[] certData) {
        this.certData = certData;
    }
}
